const db = require('../db/config');
const { sqlQueryTableDatasAll, sqlQueryTableDatas } = require('../db/sql');

module.exports.getListDatasHandler = function (req, res) {
    const tableName = req.body.field,
        cityId = Number(req.body.cityId);

    if (cityId !== 0) {
        db.query(sqlQueryTableDatas(tableName), [cityId], (error, result) => {
            if (error) {
                return res.send({
                    statusText: '获取列表出错'
                });
            } else {
                return res.send(result);
            }
        });
    } else {
        db.query(sqlQueryTableDatasAll(tableName), (error, result) => {
            if (error) {
                return res.send({
                    statusText: '获取列表出错'
                });
            } else {
                return res.send(result);
            }
        });
    }
}


